using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Telerik.Web.UI;
using OccurrencesCore.Service;
using OccurrencesCore.Utility;

namespace OccurrencesWeb.Page
{
    public partial class ApplicationConfigurationList : ExtendedPageBase
    {
        private const string MAINTENANCE_PAGE = "ApplicationConfigEdit.aspx";

        #region [ Properties ]

        /// <summary>
        /// Current Application Configuration ID.
        /// </summary>
        public int ApplicationConfigId
        {
            get { return Convert.ToInt32(ViewState[WebConstants.KEY_APPLICATION_CONFIG_ID]); }
            set { ViewState[WebConstants.KEY_APPLICATION_CONFIG_ID] = value; }
        }


        #endregion

        #region [ Page Load ]

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gvParameters.PageSize = new ConfigurationHelper().NumberGridItemsPerPage;
                //set the gridview current page
                if (Context.Items[WebConstants.KEY_GRID_PAGE_INDEX] != null)
                    gvParameters.CurrentPageIndex = Convert.ToInt32(Context.Items[WebConstants.KEY_GRID_PAGE_INDEX]);
            }
        }

        #endregion


        #region [ Events ]
        protected void OnParametersNeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            gvParameters.DataSource = new ApplicationConfigurationService().FindAll();
        }

        /// <summary>
        /// ButtonEdit click event handler.
        /// </summary>
        /// <param name="sender">Event originator.</param>
        /// <param name="e">Event args.</param>
        protected void ButtonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                int applicationConfigurationId = int.Parse(TextBoxEditCommand.Text);
                Context.Items.Add(WebConstants.KEY_APPLICATION_CONFIG_ID, applicationConfigurationId);
                Context.Items.Add(WebConstants.KEY_GRID_PAGE_INDEX, gvParameters.CurrentPageIndex);
                Response.Redirect(MAINTENANCE_PAGE);
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message, true);
            }
        }

        #endregion

    }
}
